import React, { Component } from 'react';
import Axios from 'axios'
export default class TestGeo extends Component {

    state = {
        city: '',
        city_code: '',
        province: '',
    };

    componentWillMount = () => {
        this.getPositions();
    };

    getPositions = () => {
        return new Promise(() => {
            
            Axios('/location/ip?ak=Qbzk5IG6EmeEG7woYpuK95sxPWsQHOUD').then(res => {
                console.log(res.data.content)
                this.setState({
                    city_code: res.data.content.address_detail.city_code,
                    province: res.data.content.address_detail.province,
                    city: res.data.content.address_detail.city,
                })
            })

        })
    }


    render() {
        return (
            <div>
                <p>城市ID：{this.state.city_code}</p>
                <p>省份：{this.state.province}</p>
                <p>城市：{this.state.city}</p>
            </div>
        );
    }
}
